﻿using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using Collections;

var text = "hello there";
foreach (var item in text)
{
    Console.WriteLine(item);
}

var planets = ReadPlanets();
var asList = (List<string>)planets;
asList.Clear();


var queue = new Queue<string>();
queue.Enqueue("a");
queue.Enqueue("b");
queue.Enqueue("c");

var first = queue.Dequeue();
Console.WriteLine(first);

var stk = new Stack<string>();
stk.Push("a");
stk.Push("b");
stk.Push("c");
stk.Push("d");

var top = stk.Pop();


Console.WriteLine(top);

Console.WriteLine(Calculator.Add(1, 2));
Console.WriteLine(Calculator.Add(1, 2, 3));
Console.WriteLine(Calculator.Add(1, 2, 3, 4, 5));


Console.ReadKey();

IEnumerable<T> Distinct<T>(IEnumerable<T> input)
{
    var hashSet = new HashSet<T>();
    foreach (var item in input)
    {
        if (!hashSet.Contains(item))
        {
            hashSet.Add(item);
            yield return item;
        }
    }
}
    

IEnumerable<int> GenerateEvenNumbers()
{
    for (int i = 0; i < int.MaxValue; i += 2)
    {
        Console.WriteLine($"Yielding {i}");
        yield return i;
    }
}


IEnumerable<string> ReadPlanets()
{
    var result = new List<string>
    {
        "Alderaan",
        "Coruscant",
        "Bespin"
    };

    return new ReadOnlyCollection<string>(result);
}

public class SpellChecker
{
    private readonly HashSet<string> _correctWords = new()
    {
        "dog", "cat", "fish"
    };

    public bool IsCorrect(string word) =>
        _correctWords.Contains(word);

    public void AddCorrectWord(string word) =>
        _correctWords.Add(word);
}